package com.wj.gulimall.order.listener;

import com.rabbitmq.client.Channel;
import com.wj.common.to.mq.SeckillOrderTo;
import com.wj.gulimall.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RabbitListener(queues = "order.seckill.order.queue")
public class OrderSeckillListener {
    @Autowired
    OrderService orderService;

    @RabbitHandler
    public void listener(SeckillOrderTo to, Channel channel, Message message) {
        log.info("秒杀单来了。。。。。");
        try {
            orderService.createSeckillOrder(to);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
